#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import sys
import time
import string
import xlrd
import re

if ( len(sys.argv) < 4):
	print "Miss argument!!.exit"
	exit("ahahahahah");

xlsFile=sys.argv[1];
outTxt=sys.argv[2];
tempRaw=sys.argv[3];
allRev=""
xlsWorkbook=xlrd.open_workbook(xlsFile);
xlsWorksheet=xlsWorkbook.sheet_by_name("allbugs");

resultTxtFile=open(outTxt, 'w')
tempResultTxtFile=open(tempRaw,'w');

for n in range(0,xlsWorksheet.nrows):
	selution="%s"%(xlsWorksheet.row_values(n)[10].encode('utf-8'));

	for s in selution.split('\n'):
		bugID=""
		if (s.find("CVS/SVN") > -1):
			svnUser="%s"%(xlsWorksheet.row_values(n)[9].encode('utf-8'))
			bugIDRaw="%s"%(xlsWorksheet.row_values(n)[1].encode('utf-8'))
			if ( (bugIDRaw.find("[") > -1)  and (bugIDRaw.find("]") > -1) ):
				bugID="%s"%(bugIDRaw.split('[')[1].split(']')[0])
			#elif ( (s.find("【") > -1)  and (s.find("】") > -1) ):
			#	svnRev="%s"%(s.split('【')[1].split('】')[0])
			#	resultTxtFile.write("#%s:%s\n"%(svnUser,svnRev))
			#	allRev +=",%s"%svnRev;
			#else:
				#svnRev="%s"%(s.split('：')[1])
				#resultTxtFile.write("#%s:%s\n"%(svnUser,svnRev))
			allRev +="%s:[%s]=%s\n"%(svnUser,bugID,s);
#allRev= allRev.replace(r"[^0-9]", " ")
tempResultTxtFile.write(allRev)
tempResultTxtFile.close();
resultTxtFile.close();

